package sample.pages;

import org.dreamwork.jasmine2.events.EventException;
import org.dreamwork.jasmine2.web.controls.DropdownList;
import org.dreamwork.jasmine2.web.controls.Page;
import org.dreamwork.jasmine2.web.controls.UserControl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 11-1-1
 * Time: 上午2:40
 */
public class TestControl extends UserControl {
    protected List<Map<String, String>> data = new ArrayList<Map<String, String>> ();
    protected DropdownList test;
    @Override
    public void onPagePreload (Page page) throws EventException {
        if (page == this) {
            page = this.getParent ().getPage ();
        }
        if (!page.isPostback ()) {
            for (int i = 0; i < 3; i ++) {
                Map<String, String> map = new HashMap<String, String> ();
                map.put ("value", String.valueOf (i + 1));
                map.put ("text", "item " + (i + 1) );
                data.add (map);
            }
        }
    }

    @Override
    public void onPageLoadCompleted (Page page) throws EventException {
        try {
            dataBind ();
        } catch (Throwable throwable) {
            throw new EventException (throwable);
        }
    }
}
